home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_09_08 / 9n08098a < prev    next >
Text File  |  1991-06-15  |  382b  |  19 lines

  1. int wordcount(char *str)
  2. {
  3. int count = 0;
  4. char *s;
  5. s=str;       
  6. while(*s && *s==' ')
  7.     s++;     //Skip leading spaces       
  8. while(s)
  9.     {
  10.     s=strchr(s,' ');    //Find the first word break  
  11.     while(*s && *s==' ')
  12.         s++; //Allow for multiple spaces  
  13.     count++;  //Increment count - Note it starts as 0 not 1       
  14.     }
  15. return(count);  
  16. }     
  17.  
  18.  
  19.